﻿-var entity = ViewData["entity"] as Role
-var permissions = ViewData["permissions"] as int[]
-var groups = ViewData["groups"] as List<PermissionGroup>
-bool create = (entity.Id == 0);
%style table td { padding: 2px 5px; }
%form.validate{action="role.ivp/save",method="post"}
  _formfields
  =HTMLHelper.HiddenInput("id",entity.Id)
  #content
    .formheader
      %h1
        %img.icon24{src="img/headericons/role.gif"}
        =(create)? "Новая роль":entity.Name
    _error
    .formbody
      .field
        %label.required{for="name"} Название
        %input#name.px600.big.required.basictext{name="name",value=HTMLHelper.EscapeQuotes(entity.Name),maxlength="100"}
      .field
        %label{for="description"} Описание
        %textarea#description.px600.basictext{name="description",rows="3",maxlength="1000"}=entity.Description
      -foreach(var g in groups)
        .field    
          %h2
            =g.Name
            .padded5
              %table
                -foreach(var p in g.Permissions)
                  %tr
                    %td
                      -bool selected = permissions.Contains(p.Id)
                      %label.radio{for=String.Format("pid{0}",p.Id)}
                        =HTMLHelper.Checkbox("pid",p.Id,"",selected,true)
                        =p.Name
    .formbottom
      %div
        %button.saveandreturn#submit{type="submit",onclick="$('#returnaftersave').val('true')"} Сохранить и вернуться
        %button.save#submit{type="submit",onclick="$('#returnaftersave').val('')"} Сохранить
        %button.return{type="button",onclick="closeForm();"} Вернуться